package com.ex.shapecalc;

import com.ex.question.base.ShapeQuestion;

public class TriangleQuestion extends ShapeQuestion {
	int mLength;
	int mHeight;

	public TriangleQuestion() {
		mQuestionTypeName = "三角形面积计算";
		createQuestion();
	}

	public TriangleQuestion(int l, int h) {
		mQuestionTypeName = "三角形面积计算";
		createQuestion(l, h);
	}

	@Override
	public void CalcPerimeter() {
		double angle = Math.atan(((double) mHeight / (mLength / 2)));
		int temp1 = mHeight;
		if (angle != 0)
			temp1 = (int) (mHeight / Math.sin(angle));

		int temp2 = mHeight;
		if (angle != Math.PI / 2) {
			temp2 = (int) (mHeight / Math.sin(Math.PI - angle));
		}
		mPerimeter = mLength + temp1 + temp2;
	}

	@Override
	public void CalcArea() {
		this.mPerimeter = mHeight * mLength / 2;
	}

	public void createQuestion() {
		createQuestion(mRand.getRandom10(), mRand.getRandom10());
	}

	public void createQuestion(int l, int h) {
		mLength = l;
		mHeight = h;
		CalcArea();
		CalcPerimeter();
	}
}
